<% content_for :head do -%>
  <%= stylesheet_link_tag 'tables.css' %>
<% end %>
<div id='order-wrapper' class='twelve'>
  <div class='seven large-7 columns'>
    <h1>Order Summary</h1>

    <div id='order-items-summary'>
      <% i = 1 %>
      <% @order.order_items.group_by(&:variant_id).each do |variant_id, items| %>
        <div id='order-item-<%= i %>' class='callout'>
          <%= render :partial => 'order_item', :locals => {:items => items } %>
        </div>
        <% i += 1 %>
      <% end %>
    </div>
    <div class='row'>
      <div id='final-order-shipping-address' class=' four large-6 columns radius' >
        <div class='callout'>
          <h5>Shipping Address</h5>
          <%= render :partial => '/shared/compact_address', :locals => {:shopping_address => @order.ship_address} %>
          <%= link_to 'Change address', shopping_addresses_path, :class => 'button tiny green' %>
        </div>
      </div>
      <div id='final-order-shipping-address' class=' four large-6 columns radius last' >
        <div class='callout'>
          <h5>Billing Address</h5>
          <%= render :partial => '/shared/compact_address', :locals => {:shopping_address => @order.bill_address} %>
          <%= link_to 'Change address', shopping_billing_addresses_path, :class => 'button tiny green' %>
        </div>
      </div>
    </div>
  </div>
  <div class='pretty_table five large-5 columns last'>
    <table>
      <thead>
        <tr class='odd'>
          <th class='column1_header'>
            Item
          </th><th>Price:</th><th>Price + Tax</th>
        </tr>
      </thead>
      <% @order.order_items.each do |item| %>
        <tr class='<%= cycle("odd", "")%> '>
          <td><%= item.variant.product.name %></td><td><%= number_to_currency item.price %></td><td><%= number_to_currency item.total %></td>
        </tr>
      <% end %>
      <tr class='odd'>
        <td></td><td>Sub-total:</td><td><%= number_to_currency @order.sub_total %></td>
      </tr>
      <tr>
        <td></td><td>Shipping Charges:</td><td><%= number_to_currency @order.shipping_charges %></td>
      </tr>
      <% if @order.coupon_amount > 0.0 %>
        <tr>
          <td></td><td>Coupon:</td><td><%= number_to_currency @order.coupon_amount %></td>
        </tr>
      <% end %>
      <% if @order.deal_amount && @order.deal_amount > 0.0 %>
        <tr>
          <td></td><td>Promotion:</td><td><%= number_to_currency @order.deal_amount %></td><td></td>
        </tr>
      <% end %>
      <tr>
        <td></td><td>Tax:</td><td><%= number_to_currency @order.taxed_amount %></td>
      </tr>
      <% if @order.amount_to_credit && @order.amount_to_credit > 0.0 %>
        <tr class='odd'>
          <td></td>
          <td>Credits:</td><td></td>
          <td><%= number_to_currency @order.amount_to_credit %></td>
        </tr>
      <% end %>

      <tfoot>
        <tr class='even'>
          <td></td><td>Total:</td><td><em><%= number_to_currency @order.credited_total %></em></td>
        </tr>
      </tfoot>
    </table>
    <div>
  </div>
    <%= form_tag( shopping_order_path(@order),
                                  method: :put,
                                  html:  {class: 'custom'},
                                  id:    'purchase_order') do  %>

      <div class="field ">
        <%= label_tag  :name %>
      </div>
<div class='clear'></div>
      <div class='row'>
        <div class="field six large-6 column">
          <%= label_tag 'First' %>
           <%= text_field_tag(:first_name, @credit_card.first_name) %>
        </div>

        <div class="field six large-6 column">
          <%= label_tag :last_name, 'Last' %>
           <%= text_field_tag(:last_name, @credit_card.last_name) %>
        </div>
      </div>
      <div class='clear'></div>
      <div class='row'>
        <div class="field twelve large-8 column">
          <%= label_tag 'Number'%>
           <%= text_field_tag(:number, @credit_card.number , class: ' disableAutoComplete', :autocomplete => "off") %>
        </div>
        <div class="field three large-3 column">
          <%= label_tag :verification_value, 'VCC'%>
           <%= text_field_tag(:verification_value, @credit_card.verification_value , class: 'disableAutoComplete', :autocomplete => "off") %>
        </div>
      </div>
      <div class='twelve large-12 clearfix custom'>
        <div class='row'>

          <div class="field column large-6">
            <%= label_tag :type, 'Type'%>
             <%= select_tag(:type,
                            options_for_select(
                              ['visa', 'mastercard'],
                              selected: @credit_card.type
                            )) %>
          </div>

          <div class="field column large-3">
            <%= label_tag :month %>
            <%= select_tag(:month,
                           options_for_select(
                             ['01', '02',  '03', '04', '05', '06', '07', '08', '09', '10', '11', '12' ],
                             selected: @credit_card.month
                           )) %>
          </div>

          <div class="field column large-3">
            <%= label_tag :year %>
             <%= select_tag(:year,
                            options_for_select(
                              (Time.zone.now.year..(Time.zone.now.year + 10)),
                              selected: @credit_card.year
                            )) %>
          </div>
        </div>
      </div>


      <%= submit_tag 'Complete Order', class: 'button success' %>
    <% end %>
  </div>
</div>

